package appx.craft.asd.ui;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import appx.craft.asd.R;
import appx.craft.asd.uc.ApplicationTopBar;

// TODO: Auto-generated Javadoc
/**
 * The Class InputActivity.
 */
public class InputActivity extends Activity implements OnClickListener,OnTouchListener,OnFocusChangeListener{
	
	/** The tag. */
	public final String TAG = InputActivity.class.getCanonicalName();
	
	/** The m top bar. */
	private ApplicationTopBar mTopBar;
	
	/** The btn_inputscreen_cancel. */
	private Button btn_inputscreen_send,btn_inputscreen_cancel;
	
	private EditText editTextTemp;
	
	private EditText editLogoName;
	
    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input_screen);
        mTopBar = (ApplicationTopBar)findViewById(R.id.top_bar_application);
        mTopBar.setTitle(getResources().getString(R.string.activity_inputscreen));
        mTopBar.setOnTouchListener(this);
        
        editLogoName = (EditText)findViewById(R.id.edittext_change_logo);
        editLogoName.setOnFocusChangeListener(this);
        
        btn_inputscreen_send = (Button)findViewById(R.id.btn_inputscreen_send);
        btn_inputscreen_send.setOnClickListener(this);
        btn_inputscreen_cancel = (Button)findViewById(R.id.btn_inputscreen_cancel);
        btn_inputscreen_cancel.setOnClickListener(this);
    }
    
    /* (non-Javadoc)
     * @see android.app.Activity#onStart()
     */
    @Override
	protected void onStart() {
		super.onStart();
		Log.d(TAG,"[ onStart ] ");
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onStop()
	 */
	@Override
	protected void onStop() {
		super.onStop();
		Log.d(TAG,"[ onStop ] ");
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onPause()
	 */
	@Override
	protected void onPause() {
		super.onPause();
		Log.d(TAG,"[ onPause ] ");
		hideKeyBoard();
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
		Log.d(TAG,"[ onResume ] ");
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onDestroy()
	 */
	@Override
	protected void onDestroy() {
		super.onDestroy();
		Log.d(TAG,"[ onDestroy ] ");
	}

	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		int buttonID = v.getId();
		switch (buttonID) {
		case R.id.btn_inputscreen_send:
			Toast.makeText(getApplicationContext(),"Pressed Send",Toast.LENGTH_SHORT).show();
			break;
		case R.id.btn_inputscreen_cancel:
			Toast.makeText(getApplicationContext(),"Pressed Cancel",Toast.LENGTH_SHORT).show();
			break;

		default:
			break;
		}
	}

	/* (non-Javadoc)
	 * @see android.view.View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent)
	 */
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
		return false;
	}
	
	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		View mView = v;
		if(mView instanceof EditText){
			editTextTemp = (EditText) mView;
			hideKeyBoard((EditText)mView);
		}
	}
	
	public void hideKeyBoard(EditText editTextTemp){
		InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
		if(editTextTemp != null){
			imm.hideSoftInputFromWindow(editTextTemp.getWindowToken(), 0);
		}
	}
	public void hideKeyBoard(){
		InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(editTextTemp.getWindowToken(), 0);
	}
	
    
    
}
